﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RN.ERP.BLL;
using RN.ERP.DTO;
using Newtonsoft.Json;
using RN.ERP.BLL.Material;

namespace RN.ERP.Web.Material.Material
{
    /// <summary>
    /// MaterialHandler 的摘要说明
    /// </summary>
    public class MaterialHandler : IHttpHandler
    {
        MaterialClassBLL mcBll = new MaterialClassBLL();

        public void ProcessRequest(HttpContext context)
        {
            GetTree(context);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public void GetTree(HttpContext context)
        {
            List<NodeEntity> nodes = new List<NodeEntity>();
            string parentsid = string.Empty;
            if (context.Request.QueryString["pid"] != null)
            {
                parentsid = context.Request.QueryString["pid"].Trim();
            }
            List<DTO.MateClass> items = mcBll.GetList(parentsid);
            foreach (var item in items)
            {
                NodeEntity node = new NodeEntity();
                node.isexpand = false;
                node.pid = item.cPMCCode;
                node.text = item.cMCName;
                node.id = item.cMCCode;
                node.code = item.cMCCode;
                node.children = new List<NodeEntity>();
                nodes.Add(node);
            }
            UtilitiesTool.OutputData(JsonConvert.SerializeObject(nodes), string.Empty);
        }
    }
}